After the following statements have executed,
String str = new String("alphabet soup"); int len = str.length();
what value is in the
variable len
?
13. (Remember to count the space character.)
Look again at the method call (the second statement, which uses "dot notation" to specify the method.)
String str = new String("alphabet soup"); int len = str.length(); | | | | | +---- a parameter list with no parameters | | | +---- the name of the method that is to be run | +---- the reference to the object that contains the method
The second statement contains a method call.
This is a request to run a method of an object.
The object referenced by str
contains a method length()
which, when called,
returns the number of characters in the string.
The length()
method does not require any parameters.
The parameter list in the method call str.length()
is empty.